'use strict';
/* jshint mocha: true */

var path = require('path');
var expect = require('chai').expect;
var Injector = require('injector');
var Q = require('q');
var _ = require('lodash');

var projectPath = path.resolve(__dirname, '..');
var includePaths = [projectPath + '/lib', projectPath + '/example'];

describe('test/test_instance', function () {
    it('#it should have 2 instance of mongodb client', function (done) {
        function test(mongodb) {
            // jshint -W030
            expect(_.keys(mongodb)).to.deep.equal(['main1', 'main2']);
            expect(Q.isPromise(mongodb.main1)).to.be.true;
            expect(Q.isPromise(mongodb.main2)).to.be.true;
            return mongodb.main1.then(function (db) {
                expect(db).to.be.an.object;
                return Q.ninvoke(db, 'collections')
                    .then(function (collections) {
                        expect(collections).to.be.empty;
                    });
            });
            // jshint +W030
        }
        var injector = new Injector(includePaths, {});
        var moduleDefinition = Injector.define([
            'component/mongodb'
        ], test);
        // jshint -W064
        Q(injector.inject(moduleDefinition)).nodeify(done);
        // jshint +W064
    });
});